package com.green.common.fusionchart.utils;

import java.util.List;

import org.dom4j.Element;

import com.green.common.fusionchart.Apply;
import com.green.common.fusionchart.Categories;
import com.green.common.fusionchart.Chart;
import com.green.common.fusionchart.DataSet;
import com.green.common.fusionchart.Line;
import com.green.common.fusionchart.MSCombiDY2D;
import com.green.common.fusionchart.MSLine;
import com.green.common.fusionchart.Pie2D;
import com.green.common.fusionchart.Pie3D;
import com.green.common.fusionchart.Set;
import com.green.common.fusionchart.SingleColumn2D;
import com.green.common.fusionchart.StackedColumn2D;
import com.green.common.fusionchart.Style;

public class ChartHelper{

	/**
	 * 得到自己设定的各个属性报表图形字符串
	 * @param chart
	 * @return
	 * @throws Exception 
	 */
	public static String getDefaultChart(Chart chart) throws Exception {
		
		XmlHelper.validateCount(chart);
		if(chart.getStyles() == null || chart.getStyles().size() == 0){
			List<Style> styles = DefaultHelper.getDefaultStyles();
			List<Apply> applys = DefaultHelper.getDefaultApply();
			chart.setStyles(styles);
			chart.setApplys(applys);
		}
		Element root = XmlHelper.getElement("chart");
		root = XmlHelper.setAttributeForElement(root, chart);
		
		return root.asXML();
	}
	
	
	/**
	 * 得到默认的曲线报表图形
	 * @param category
	 * @param dataSets
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultMSLine(Categories category, List<DataSet> dataSets, String caption, String subCaption) throws Exception{
		MSLine line = new MSLine();
		line.setCaption(caption);
		line.setSubCaption(subCaption);
		line.setCategories(category);
		line.setDataSets(dataSets);
		return getDefaultChart(line);
	}
	
	/**
	 * 得到默认的曲线报表图形
	 * @param category
	 * @param dataSets
	 * @param trendlines 趋势线
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultMSLine(Categories category, List<DataSet> dataSets, String caption, String subCaption,List<Line> lineList) throws Exception{
		MSLine line = new MSLine();
		line.setCaption(caption);
		line.setSubCaption(subCaption);
		line.setCategories(category);
		line.setDataSets(dataSets);
		line.setLines(lineList);
		return getDefaultChart(line);
	}
	
	
	/**
	 * 得到默认的柱状报表2D图形
	 * @param sets
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultSingleColumn2D(List<Set> sets, String caption, String subCaption) throws Exception{
		SingleColumn2D column = new SingleColumn2D();
		column.setCaption(caption);
		column.setSubCaption(subCaption);
		column.setSets(sets);
		return getDefaultChart(column);
	}
	
	/**
	 * 得到默认的柱状报表2D图形
	 * @param sets
	 * @param trendlines 趋势线
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultSingleColumn2D(List<Set> sets, String caption, String subCaption,List<Line> lineList) throws Exception{
		SingleColumn2D column = new SingleColumn2D();
		column.setCaption(caption);
		column.setSubCaption(subCaption);
		column.setSets(sets);
		column.setLines(lineList);
		return getDefaultChart(column);
	}
	

	/**
	 * 得到默认的叠柱状报表2D图形
	 * @param sets
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultStackedColumn2D(Categories category,List<DataSet> dataSets, String caption, String subCaption) throws Exception{
		StackedColumn2D column = new StackedColumn2D();
		column.setCaption(caption);
		column.setSubCaption(subCaption);
		column.setCategories(category);
		column.setDataSets(dataSets);
		return getDefaultChart(column);
	}
	
	/**
	 * 得到默认的叠柱状报表2D图形
	 * @param sets
	 * @param trendlines 趋势线
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultStackedColumn2D(Categories category,List<DataSet> dataSets, String caption, String subCaption,List<Line> lineList) throws Exception{
		StackedColumn2D column = new StackedColumn2D();
		column.setCaption(caption);
		column.setSubCaption(subCaption);
		column.setCategories(category);
		column.setDataSets(dataSets);
		column.setLines(lineList);
		return getDefaultChart(column);
	}
	
	/**
	 * 得到默认的柱状与曲线结合的报表图形字符串
	 * @param category
	 * @param dataSets
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultMSCombiDY2D(Categories category, List<DataSet> dataSets, String caption, String subCaption) throws Exception{
		MSCombiDY2D combi = new MSCombiDY2D();
		combi.setCaption(caption);
		combi.setSubCaption(subCaption);
		combi.setCategories(category);
		combi.setDataSets(dataSets);
		return getDefaultChart(combi);
	}
	
	/**
	 * 得到默认的柱状与曲线结合的报表图形字符串
	 * @param category
	 * @param dataSets
	 * @param trendlines 趋势线
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultMSCombiDY2D(Categories category, List<DataSet> dataSets, String caption, String subCaption,List<Line> lineList) throws Exception{
		MSCombiDY2D combi = new MSCombiDY2D();
		combi.setCaption(caption);
		combi.setSubCaption(subCaption);
		combi.setCategories(category);
		combi.setDataSets(dataSets);
		combi.setLines(lineList);
		return getDefaultChart(combi);
	}
	
	/**
	 * 得到默认的2D饼图报表图形字符串
	 * @param sets
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultPie2D(List<Set> sets, String caption, String subCaption) throws Exception{
		Pie2D pie = new Pie2D();
		pie.setCaption(caption);
		pie.setSubCaption(subCaption);
		pie.setSets(sets);
		
		return getDefaultChart(pie);
	}
	
	/**
	 * 得到默认的3D饼图报表图形字符串
	 * @param sets 
	 * @return
	 * @throws Exception
	 */
	public static String getDefaultPie3D(List<Set> sets, String caption, String subCaption) throws Exception{
		Pie3D pie = new Pie3D();
		pie.setSets(sets);
		pie.setCaption(caption);
		pie.setSubCaption(subCaption);
		return getDefaultChart(pie);
	}

}
